<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}"
	rel="stylesheet" />
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<div class="form-group">
				<label class="col-sm-3 control-label ">微信名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wxName" id="wxName" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">微信号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wxCode" id="wxCode">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">appId：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="appId" id="appId">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">appSecret：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="appSecret"
						id="appSecret">
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script
		th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script type="text/javascript">
		$("#form-role-add").validate({
			rules:{
				wxName:{
					required:true,
				},
				wxCode:{
					required:true,
					remote: {
		                url: ctx + "system/weixin/wxCode/checkWxCodeUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"wxCode" : function() {
		                        return $.common.trim($("#wxCode").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				appId:{ required:true, },
				appSecret:{ required:true, },
			},
			messages: {
		        "wxCode": { remote: "微信号已经存在" }
		    }
		});
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
		function add() {
			var wxName = $("input[name='wxName']").val();
			var wxCode = $("input[name='wxCode']").val();
			var appId = $("input[name='appId']").val();
			var appSecret = $("input[name='appSecret']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/weixin/wxCode/add",
				data : {
					"wxName": wxName,
					"wxCode": wxCode,
					"appId": appId,
					"appSecret": appSecret
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
